'use strict';
const db = uniCloud.database();
const recipeModel = require('./models/recipe.js')
exports.main = async (event, context) => {
	uniCloud.logger.info('event : ', event)
	let res = {};
	switch (event.action) {
		case 'pageQueryRecipe':
			const pageQueryRecipeRes = await recipeModel.pageQueryRecipe(event.page);
			res = pageQueryRecipeRes;

			break;
		case 'queryRecipeInfo':
			const recipeInfoRes = await recipeModel.queryRecipeInfoByRecipeCode(event.recipe_code);
			res.recipeInfo = recipeInfoRes.data;
			break;
		case 'queryRecipeDetail':
			const recipeIngredientsRes = await recipeModel.queryRecipeIngredientsByRecipeCode(event
			.recipe_code);
			res.recipeIngredients = recipeIngredientsRes.data;

			const recipeStepsRes = await recipeModel.queryRecipeStepsByRecipeCode(event.recipe_code);
			res.recipeSteps = recipeStepsRes.data;

			break;
		default:
			await recipeModel.pageQueryRecipe(event.page);
			console.log("api未定义");
			break;

	}
	uniCloud.logger.info('res:', res)
	return res
};
